import request from '@/utils/request'

export interface spuPageModel {
    records: spuModel[],
    total: number,
    size: number,
    current: number,
    searchCount: number,
    pages: number
}

export interface baseSaleAttrModel {
    id: number,
    name: string,
}

export interface spuModel {
    id?: number,
    spuName: string,
    description: string,
    category3Id: number,
    tmId: number | undefined,
    spuSaleAttrList: saleAttrModel[],
    spuImageList: spuImageModel[]
}

export interface spuImageModel {
    id?: number,
    spuId?: number,
    imgName: string,
    imgUrl: string,
    name?: string,
    url?: string,
    response?: any,
    isDefault?: string
}

export interface saleAttrValueModel {
    id?: number,
    spuId?: number,
    baseSaleAttrId: number,
    saleAttrValueName: string,
    saleAttrName?: string,
    isChecked?: null
}

export interface saleAttrModel {
    id?: number,
    spuId?: number,
    baseSaleAttrId: number,
    saleAttrName: string,
    spuSaleAttrValueList: saleAttrValueModel[],
    inputVisible?: boolean,
    saleAttrIdValId?: string
}

export default {
    // 获取spu页面基本信息
    getSpuPage(page: number, limit: number, category3Id?: number) {
        return request.get<any, spuPageModel>(`/admin/product/${page}/${limit}`, {
            params: {
                category3Id: category3Id
            }
        })
    },
    // 获取销售属性
    baseSaleAttrList() {
        return request.get<any, baseSaleAttrModel[]>('/admin/product/baseSaleAttrList')
    },
    // 保存接口
    saveSpuInfo(spuForm: spuModel) {
        return request.post<any, null>('/admin/product/saveSpuInfo', spuForm)
    },
    // 获取当前spuId的销售属性
    spuSaleAttrList(spuId: number) {
        return request.get<any, saleAttrModel[]>(`/admin/product/spuSaleAttrList/${spuId}`)
    },
    // 获取当前spuId的图片列表
    spuImageList(spuId: number) {
        return request.get<any, spuImageModel[]>(`/admin/product/spuImageList/${spuId}`)
    },
    // 更新spu
    updateSpuInfo(spuForm: spuModel) {
        return request.post<any, null>(`/admin/product/updateSpuInfo`, spuForm)
    },
    // 删除spu
    deleteSpu(spuId: number) {
        return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`)
    }
}